<template>
  <el-dialog title="选择细分商品" :visible.sync="visible" width="1500px" append-to-body>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"  label-width="80px">
      <el-form-item label="商品标题" prop="skuTitle">
        <el-input
          v-model="queryParams.skuTitle"
          placeholder="请输入商品标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原价" prop="skuPrice">
        <el-input
          v-model="queryParams.skuPrice"
          placeholder="请输入原价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="GoodsSkuInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="细分商品主键" align="center" prop="skuId" />
      <el-table-column label="商品" align="center" prop="goodsName" />
      <el-table-column label="商品标题" width="700px" align="center" prop="skuTitle" />
      <el-table-column label="原价(市场标价格)" align="center" prop="skuPrice" />
      <el-table-column label="当前价格" align="center" prop="skuNowPrice" />


    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getSkuList"
    />


    <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取 消</el-button>
        <el-button type="primary" @click="onSubmit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { listGoodsSkuInfo  } from "@/api/webshop/GoodsSkuInfo";

export default {
  name: "GoodsSkuModal",
  data() {
    return {
      visible: false,
      skuList: [],

      // 遮罩层
      loading: true,
      // 选中数组
      skus: [],
      // 总条数
      total: 0,
      // 商品细分表格数据
      GoodsSkuInfoList: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsId: null,
        supplierId: null,
        skuTitle: null,
        skuPrice: null,
        skuState: null,
        safeguardTypeIds: null,
        skuIds : null
      },
    }
  },
  methods: {
    init(supplierId, skuIds) {
      console.log("skuIds: ",  skuIds )
      this.visible = true
      this.$nextTick(() => {
        this.getSkuList( supplierId, skuIds )
      })
    },
    getSkuList( supplierId , skuIds ) {
      this.loading = true;

      this.queryParams.supplierId = supplierId
      this.queryParams.skuIds = skuIds.join()



      listGoodsSkuInfo(this.queryParams).then(response => {
        this.GoodsSkuInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    onSubmit(){

      if(this.skus==null  ||  this.skus.length <= 0 ){
        this.$message({
          message: '请选择细分商品',
          type: 'warning'
        })
      }else{
        this.$emit('selectSkuList',this.skus)
        this.visible = false
      }

    },


    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getSkuList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.skus = selection
    },

  }
}
</script>


<style scoped lang="scss">

</style>
